package com.wkhyapp.lm.view;

import android.graphics.Color;
import android.os.Build;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.loadmore.LoadMoreView;
import com.wkhyapp.lm.R;
import com.wkhyapp.lm.adapter.NoticeAdapter;
import com.wkhyapp.lm.adapter.ShangJiaAdapter;
import com.wkhyapp.lm.base.SuperActivity;
import com.wkhyapp.lm.contract.SYSJPresenter;
import com.wkhyapp.lm.contract.SYSJView;
import com.wkhyapp.lm.http.vo.Member;
import com.wkhyapp.lm.http.vo.Notice;
import com.wkhyapp.lm.http.vo.ThinkUser;
import com.wkhyapp.lm.utils.StatusBarFontUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class SYSJActivity extends SuperActivity<SYSJPresenter> implements SYSJView {



    @BindView(R.id.back_iv)
    ImageView back_iv;
    @BindView(R.id.refresh_view)
    SwipeRefreshLayout refresh_view;
    @BindView(R.id.recycler_view)
    RecyclerView recycler_view;
    private ShangJiaAdapter shangJiaAdapter;
    private List<ThinkUser> members;
    private int mCurrentPage = 1;
    @BindView(R.id.set_tv)
    TextView set_tv;

    @Override
    public void initUI() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            translucentStatusBar();
        }
        StatusBarFontUtil.setLightStatusBarColor(this);

        members = new ArrayList<>();
        shangJiaAdapter = new ShangJiaAdapter(R.layout.item_admin_user,members);
        refresh_view.setColorSchemeColors(Color.parseColor("#FFEC48"),Color.parseColor("#FFEC48"));
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recycler_view.setLayoutManager(manager);
        recycler_view.setAdapter(shangJiaAdapter);
        refresh_view.setRefreshing(false);
        mPresenter.getData(1);

    }

    @Override
    protected void initListener() {
        back_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        shangJiaAdapter.setLoadMoreView(new LoadMoreView() {
            @Override
            public int getLayoutId() {
                return R.layout.view_index_load_more;
            }

            @Override
            protected int getLoadingViewId() {
                return com.chad.library.R.id.load_more_loading_view;
            }
            @Override
            protected int getLoadFailViewId() {
                return com.chad.library.R.id.load_more_load_fail_view;
            }
            @Override
            protected int getLoadEndViewId() {
                return com.chad.library.R.id.load_more_load_end_view;
            }
        });

        shangJiaAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {
                mCurrentPage = mCurrentPage+1;
                mPresenter.getDataMore(mCurrentPage);

            }
        });
        refresh_view.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mCurrentPage = 1;
                mPresenter.getData(mCurrentPage);
            }
        });
    }


    @Override
    public void setMemberList(List<ThinkUser> memberList,Integer totals){
        members.clear();
        if(memberList!=null&&memberList.size()>0){
            members.addAll(memberList);

        }
        shangJiaAdapter.notifyDataSetChanged();
        refresh_view.setRefreshing(false);
        shangJiaAdapter.loadMoreComplete();

        set_tv.setText("所有商家（"+totals+")");

    }

    @Override
    public void setMemberMoreList(List<ThinkUser> memberList) {
        if(memberList.size()==0){
            shangJiaAdapter.loadMoreComplete();
            shangJiaAdapter.loadMoreEnd();
        }else{
            members.addAll(memberList);
            shangJiaAdapter.notifyDataSetChanged();
            shangJiaAdapter.loadMoreComplete();
        }
    }

    @Override
    protected SYSJPresenter createPresenter() {
        return mPresenter = new SYSJPresenter(this);
    }


    @Override
    protected void afterCreate() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_sysj;
    }

}
